<!--
 * @Description: 04-回文检查器
 * @Autor: wangxin
 * @Date: 2020-06-10 09:52:59
 * @LastEditors: Seven
 * @LastEditTime: 2020-06-10 13:33:23
-->
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./deque.js"></script>
    <script>
      function palindromeChecker(aString) {
        if (
          aString === undefined ||
          aString === null ||
          (aString !== null && aString.length === 0)
        ) {
          return false
        }

        const deque = new Deque()
        const lowerString = aString.toLocaleLowerCase().split('').join(' ') // 转换为小写
        let isEqual = true // 是否相等
        let firstChar, lastChar

        for (let i = 0; i < lowerString.length; i++) {
          deque.addBack(lowerString.charAt(i))
        }

        while (deque.size() > 1 && isEqual) {
          firstChar = deque.removeFront()
          lastChar = deque.removeBack()
          if (firstChar !== lastChar) {
            isEqual = false
          }
        }

        return isEqual
      }

      // 代码测试
      console.log('kzyak', palindromeChecker('kzyak'))
      console.log('kayak', palindromeChecker('kayak'))
    </script>
  </body>
</html>
